package com.aruba.bulethoothdemoapplication.view;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.aruba.bulethoothdemoapplication.R;
import com.aruba.bulethoothdemoapplication.model.BleDevice;
import com.aruba.bulethoothdemoapplication.viewmodel.SelectDeviceViewModel;

public class MainActivity extends AppCompatActivity implements SelectDeviceFragment.OnListFragmentInteractionListener {
    private NavController navController;
    private SelectDeviceViewModel selectDeviceViewModel;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        selectDeviceViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(SelectDeviceViewModel.class);

        navController = Navigation.findNavController(this, R.id.fragmentContainerView);
        AppBarConfiguration configuration = new AppBarConfiguration
                .Builder(navController.getGraph())
                .build();
        NavigationUI.setupActionBarWithNavController(this, navController, configuration);
    }

    @Override
    public boolean onSupportNavigateUp() {
        return navController.navigateUp();
    }

    @Override
    public void onListFragmentInteraction(BleDevice item) {
        selectDeviceViewModel.setSelectBleDevice(item);
        navController.navigate(R.id.action_itemFragment_to_printFragment);
    }
}
